import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'
import DZCL from '@/components/DZCL'
import DZCLA from '@/components/DZCLA'
import DataBase from '@/components/DataBaseMan'
import InitDataBase from '@/components/initDataBase'
import Login from '@/components/Login'
import QrCode from '@/components/qrCode'
import EngCode from '@/components/EngCode'
import addQty from '@/components/addQty'
import addInv from '@/components/addInv'
import Feeding from '@/components/Feeding'
import orderList from '@/components/orderList'
import CompleteOrder from '@/components/CompleteOrder'
import orderDetail from '@/components/orderDetail'
import { Toast } from 'vant';
import vueGoodTablePlugin from 'vue-good-table';
import 'vue-good-table/dist/vue-good-table.css'



Vue.use(Router,vueGoodTablePlugin)

const router = new Router({
  routes: [
    {
      path: '/login',
      name: 'Login',
      component: Login
    },
    {
      path: '/',
      name: 'Home',
      component: Home
    },
    {
      path: '/dzcl',
      name: 'DZCL',
      component: DZCL
    },
    {
      path: '/dzcla',
      name: 'DZCLA',
      component: DZCLA
    },
    {
      path: '/dataBase',
      name: 'DataBase',
      component: DataBase
    },
    {
      path: '/initDataBase',
      name: 'InitDataBase',
      component: InitDataBase
    },
    {
      path: '/qrCode',
      name: 'QRCode',
      component: QrCode
    },
    {
      path:'/engCode',
      name:'EngCode',
      component:EngCode
    },
    {
      path:'/addQty',
      name:'addQty',
      component:addQty
    },
    {
      path:'/addInv',
      name:'addInv',
      component:addInv
    },
    {
      path:'/orderList',
      name:'orderList',
      component:orderList
    },
    {
      path:'/orderDetail',
      name:'orderDetail',
      component:orderDetail
    },
    {
      path:'/feeding',
      name:'Feeding',
      component:Feeding
    },
    {
      path:'/CompleteOrder',
      name:'CompleteOrder',
      component:CompleteOrder
    }
  ]
})


router.beforeEach((to, from, next) => {
  var userInfo = JSON.parse(sessionStorage.getItem("_sessionlogin"));
  if (to.path != '/login') {
    if (userInfo && userInfo.account) {
      next();
    } else {
      Toast("请先登录");
      next("/login");
    }
  } else {
    next();
  }
});


export default router; 
